package cn.adkii.springframework.beans.factory.support;

import cn.adkii.springframework.beans.BeansException;
import cn.adkii.springframework.beans.factory.config.BeanDefinition;

/**
 * @author malingdi
 * @description
 * @date 2023/11/20 14:46
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{
    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        }catch (InstantiationException | IllegalStateException e){
            throw new BeansException("Instantiation of bean failed", e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        addSingleton(beanName, bean);
        return bean;
    }
}
